home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Essentials / MacApp Documentation / MacApp.TECH$ Archives / 1990 / Feb 90 / MacApp.Tech$ 2⁄23⁄90 / 0705-Nested Each with del-Feb90 < prev    next >
Encoding:
Text File  |  1991-03-06  |  1.5 KB  |  52 lines  |  [TEXT/GEOL]

  1. Item forwarded  by  A33          to A34
  2.  
  3. Item    5649548                         18-Feb-90        14:54PST
  4.  
  5. From:   AUST0334                        AUDev - CRIA, Canberra, ACT,IDV
  6.  
  7. To:     MACAPP.TECH$                    MacApp Technical
  8.  
  9. Sub:    Nested Each with deletions
  10.  
  11. I am using MacApp to develop a Paper Form generation package, and recently had
  12. cause to delete an element from a TList while in a method called under
  13. TList.Each, and then enter another Each loop.
  14.  
  15. Now, I admit that this may seem quite strange, but is valid and sensible in the
  16. context I was using it.
  17. ( the first loop was processing DeSelection, and the second invoked a resulting
  18. update of screen layout.)
  19.  
  20.  
  21. Apparently the MacApp programmers consider this sensible also, as they seem to
  22. have mechanisms in place to cope with it. (i.e the fEachLevel counter and
  23. associated mechanisms).
  24.  
  25. Unfortunately it failed, and the second invocation of Each did not process the
  26. last element in the list.
  27.  
  28. The fix is, however, quite simple and safe.
  29. The loop which does the work in TList.Each normally looks like this:-
  30.  
  31.    for index := 1 to fSize do
  32.    begin
  33.        LONGINT(item) := PLongInt(Ord(Handle(SELF)^) + offset)^;
  34.     if Ord(item) <> kDeletedElement then
  35.      DoToItem(item);
  36.     offset := offset + kElemSize;
  37.    end;
  38.  
  39. The fix is to modify the loop line to look like this :-
  40.    for index := 1 to (fSize + fDeletions) do
  41.  
  42. This ensures that the index traverses all the valid items and the deleted ones
  43. which have not yet been compacted out.
  44.  
  45. Towards more unbreakable code,
  46.  
  47. Don Lawn
  48.  
  49.  
  50.  
  51.  
  52.